﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class ABPOSController : ITXController
    {

        [ChildActionOnly]
        public ActionResult MAB50RZ(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.IsVAFReady = MABF.IsVAFReady;
            ViewBag.IsVAReady = MABF.IsVAReady;
            ViewBag.IsWFReady = MABF.IsWFReady;
            ViewBag.IsWSReady = MABF.IsWSReady;
            MABF.VAF.VAFKOLL = "SHW  ";
            AUTOCHK();
            ViewBag.ReturnUrl = returnUrl;
            return PartialView(MABF.VAF);
        }
        public void AUTOCHK()
        {
            PM["ARTST"] = MABF.WFART.Substring(0, 1);
            PM["KOLL"] = MABF.VAF.VAFKOLL;
            PM["ART"] = MABF.WFART.Substring(1, 20);
            PM["FARBE"] = MABF.WFART.Substring(23, 10);
            PM["DES"] = MABF.WFART.Substring(1 + 20 + 2 + 10 * 4 + 7, 20);       
            PM["RUNID"] = this.RUNID;
            PM["KRS"] = MABF.EXORD.Substring(1, 2);
            PM["AUFART"] = "VA";
            PM["ORDERNUM"] = MABF.EXORD.Substring(1, 11);
            PM["LFD"] = MABF.EXORD.Substring(3, 6);
            PM["RELOADABK"] = false;
            string ABAUF = VABK.NEWABK(PM);
            LFD = ABAUF.Substring(2, 6);
            POS = MABF.EXORD.Substring(9, 3);
            PM["ORDERNUM"] = ABAUF.Substring(0, 2) + LFD + POS + "VA ";
            PM["COLOR"] = "VA ";
            PM["AUFTYP"] = "V";
            PM["ARTSTAGE"] = "Z";
            //PM["VKAUF"] = pm["ORDERNUM"];
            PM["VKPAUF"] = KRS + LFD + POS;
            PM["VKPQTY"] = 0;//
            PM["VKAUF"] = "                  ";//
            PM["UNDES"] = "HZ000001";
            PM["DELDATE"] = VPR.date;
            PM["STARTDATE"] = VPR.date;

            VPR.NEWPLAN(PM);
            bool IsABPCreated = false;
            PM["ORDER"] = PM["ORDERNUM"];
            PM["WAKZ"] = MABF.WFART.Substring(0, 1);
         
            PM["VAR"] = "  ";
          
            PM["BESCHICH"] = MABF.WFART.Substring(33, 10);
            PM["DESS"] = MABF.WFART.Substring(43, 10);
            PM["COLORIT"] = MABF.WFART.Substring(53, 10);
            PM["GROE"] = MABF.WFART.Substring(63, 7);
            PM["MAKE2ORD"] = false;
            PM["IsDI"] = false;
            ABP.RZABPNEW(PM, ref IsABPCreated);
        }
    }
}
